﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    public class UQueue<T> : IEnumerable<T>
    {
        List<T> data;
        const int defaultSize = 4;
        public UQueue(int size = defaultSize)
        {
            data = new List<T>(size);
        }
        public T this[int index]
        {
            get { return data[index]; }
            set { data[index] = value; }
        }
        public int Count { get { return data.Count; } }

        public IEnumerator<T> GetEnumerator()
        {
            return data.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return data.GetEnumerator();
        }

        public void Enqueue(T e)
        {
            Queue queue = new Queue();
            data.Add(e);
        }

        public T Dequeue()
        {
            T tmp = default(T);
            if (Count > 0)
            {
                tmp = Peek();
                data.RemoveAt(0);
            }
            return tmp;
        }

        public T Peek()
        {
            if (Count > 0)
                return data[0];
            return default(T);
        }

        public void Clear()
        {
            data = new List<T>(defaultSize);
        }
    }
}
